package com.chance.cc.crawler.development.bootstrap.taobao.supplement;

import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import com.chance.cc.crawler.development.utils.RedisReader;
import org.apache.commons.lang3.StringUtils;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @author bx
 * @date 2020/11/11 0011 10:44
 */
public class TaobaoCommentSupplementStart {

    public static final String domainId = "taobao";

    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HEW657EL99F83S9D");
        proxy.setPassword("8916B1F3F10B1979");
    }

    public static void main(String[] args) {
        dev();
//        prod();

    }

    private static void dev(){
        RedisReader redisReader = new RedisReader("192.168.1.215",6379,4);
        String requestQueueName = StringUtils.joinWith("-","crawler",domainId,"comment","supplement","queue");
        CrawlerRequestRecord requestRecord = redisReader.recordPop(
                requestQueueName+"_list", requestQueueName+"_map");

        //user agents source record
        CrawlerRequestRecord userAgentsCrawlerRecord = CrawlerRequestRecord.builder()
                .startPageRequest("taobao_comment_user_agents", turnPageItem)
                .httpUrl("https://fake-useragent.herokuapp.com/browsers/0.1.11")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .crawlerThreadNum(1)
                .triggerInfo(domainId,domainId,System.currentTimeMillis(),domainId)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(requestQueueName))
                .consoleResultPipeline()
                .fileResultPipeline("D:\\chance\\log\\taobao\\taobao_comment.log",false)
                .requestRecord(requestRecord)
                .supportRecord(userAgentsCrawlerRecord)
                .build().start();
    }
}
